<?php namespace Phpcmf\Model\Zone;

// 模块内容模型类

class Content extends \Phpcmf\Model\Content {


    // 内容发布之前
    public function _content_post_before($id, $data, $old) {

        if ($this->table($this->mytable)->where('id<>'.$id)->where('uid', (int)$data[1]['uid'])->counts()) {
            \Phpcmf\Service::C()->_json(0, '一个账号只能创建一个空间');
        }

        return $data;
    }


    // 判断关注
    public function is_guanzhu($uid, $id) {

        if (!$uid) {
            return 0;
        }

        return $this->table($this->mytable.'_form_fensi')->where('cid', $id)->where('uid', $uid)->counts();
    }

    // 获取空间信息
    public function get_zone($uid) {

        if (!$uid) {
            return [];
        }

        $row = $this->table($this->mytable)->where('uid', $uid)->getRow();
        if (!$row) {
            return [];
        }

        $data = $this->table($this->mytable.'_data_'.intval($row['tableid']))->get($row['id']);
        $data && $row = $row + $data;

        return $row;

    }

    // 获取空间的id号
    public function get_zone_id($uid) {

        if (!$uid) {
            return 0;
        }

        $row = $this->table($this->mytable)->where('uid', $uid)->getRow();
        if (!$row) {
            return 0;
        }

        return $row['id'];

    }
}